import { defineStore } from 'pinia'
import type { MenusState } from '@/stores/modules/types/menusState'
import { constantMenus } from '@/router'
import { ascending, filterNoPermissionTree, filterTree } from '@/router/utils'
import { store } from '@/stores'

export const useMenusStore = defineStore({
  id: 'simple-menus',
  state: (): MenusState => ({
    constantMenus,
    menus: []
  }),
  actions: {
    handleMenus(routes: any) {
      this.menus = filterNoPermissionTree(filterTree(ascending(this.constantMenus.concat(routes))))
    },
    resetState() {
      this.menus = []
    }
  }
})

export function useMenusStoreHook() {
  return useMenusStore(store)
}
